#!/usr/bin/python

__author__ = 'vinoaj@gmail.com (Vinoaj Vijeyakumaar)'


from google.appengine.api import users
from google.appengine.ext import db


class UserHandler:
  def __init__(self):
    self.user_obj = self.handleUser()

  def handleUser(self):
    user = users.get_current_user()
    if not user:
      return False
    
    user_obj_query = db.GqlQuery("SELECT * FROM UserPrefs WHERE user = :1", user)
    if user_obj_query.count() is 0:
      new_user = UserPrefs(user=user)
      new_user.put()
      user_obj = new_user
    else:
      user_obj = user_obj_query[0] 
      
    return user_obj